package com.chookss.tools;

import android.app.Application;
import android.content.Context;
import android.os.Environment;
import android.os.StatFs;


import com.chookss.MyApp;

import java.io.File;

public class AppUtil {
    public static Application getApp() {
        return MyApp.appSettingCtx;
    }

    public static Context getAppContext() {
        return MyApp.appCtx;
    }
    /**
     * 检测存储空间
     *
     * @return availableBlocks * blockSize/1024/1024
     */
    public static long getRootDirectory() {

        try {
            File root = Environment.getDataDirectory();
            StatFs stat = new StatFs(root.getPath());
            @SuppressWarnings("deprecation")
            long blockSize = stat.getBlockSize();
            @SuppressWarnings("deprecation")
            long availCount = stat.getAvailableBlocks();
            return (availCount * blockSize) / 1024 / 1024;
        } catch (Exception e) {
            e.printStackTrace();
        }
        return 2; // 获取可用大小(单位 M)
    }
    /**
     * 验证手机号码是否合法
     */
    public static boolean validatePhoneNumber(String mobiles) {
        String telRegex = "^((1[0-9]))\\d{9}$";
        return !Utils.isNull(mobiles) && mobiles.matches(telRegex);
    }
}
